package com.huatai.paas.controller;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.huatai.common.api.R;
import com.huatai.common.log.annotation.Log;
import com.huatai.common.log.enums.BusinessType;
import com.huatai.paas.dto.CreateModelManagementDto;
import com.huatai.paas.dto.ModelManagement;
import com.huatai.paas.dto.ModelTransformDto;
import com.huatai.paas.dto.QueryModelManagementDto;
import com.huatai.paas.dto.info.QueryModelManagementInfo;
import com.huatai.paas.service.ModelManagementService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * <b>ModelManagementController</b>
 *
 * @description: ModelManagementController <br>
 * @date: 2024/7/22 17:05 <br>
 * @author: lhm <br>
 * @version: 1.0 <br>
 */

@Api(tags = "模型管理")
@RestController
public class ModelManagementController {
	private static final Logger logger = LoggerFactory.getLogger(ModelManagementController.class);

	@Autowired
	private ModelManagementService modelManagementService;

	@ApiOperation("分页查询模型列表")
	@PostMapping("/query/modelManagement/list")
	public R queryModelManagementList(@RequestBody QueryModelManagementDto dto){
		IPage<QueryModelManagementInfo> pageInfo = modelManagementService.queryModelManagementList(dto);
		return R.data(pageInfo);
	}

	@ApiOperation("添加模型数据")
	@PostMapping("/create/modelManagement")
	@Log(title = "模型管理",businessType = BusinessType.INSERT)
	public R createModelManagement(@RequestBody CreateModelManagementDto dto){
		return modelManagementService.createModelManagement(dto);
	}

	@ApiOperation("获取模型数据详情")
	@GetMapping("/modelManagement/detail/{modelId}")
	public R<QueryModelManagementInfo> modelManagementDetail(@PathVariable(value = "modelId") Long modelId){
		return modelManagementService.modelManagementDetail(modelId);
	}

	@ApiOperation("转换模型数据回执")
	@GetMapping("/transform/modelManagement")
	public R transformModelManagement(@RequestParam(value = "type") Integer type,
				@RequestParam(value = "itemId") Long itemId,@RequestParam(value = "status") Integer status){
		System.out.println("转换模型数据回执 type:"+type+",itemId:"+itemId+",status:"+status);
		return modelManagementService.transformModelManagement(type,itemId,status);
	}

	@ApiOperation("根据模型ID删除模型信息")
	@GetMapping("/delete/modelManagement/byId")
	@Log(title = "模型管理",businessType = BusinessType.DELETE)
	public R deleteModelManagementById(@RequestParam Long id){
		boolean status = modelManagementService.deleteModelManagementById(id);
		return R.data(status);
	}

}
